// Codigo comun para todos los kernels.
// Autor: Juan G. Campa

#ifndef _COMMON_CU_
#define _COMMON_CU_

// includes, C string library
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// includes, cuda
#include <cuda.h>
#include <builtin_types.h>
#include <cuda_runtime_api.h>

// Suma/Resta/Mult de componentes.
__device__ inline float4 operator+(const float4 &a, const float4 &b) 
{
   return make_float4(a.x+b.x, a.y+b.y, a.z+b.z, a.w+b.w);
}
__device__ inline float4 operator-(const float4 &a, const float4 &b) 
{
   return make_float4(a.x-b.x, a.y-b.y, a.z-b.z, a.w-b.w);
}
__device__ inline float4 operator*(const float4 &a, const float4 &b) 
{
   return make_float4(a.x*b.x, a.y*b.y, a.z*b.z, a.w*b.w);
}
__device__ inline float4 operator*(const float4 &a, const float &b) 
{
   return make_float4(a.x*b, a.y*b, a.z*b, a.w*b);
}

// Distance between two float4, whitout taking w into consideration.
__device__ inline float calcLength(const float4 &d)
{
    return sqrt(d.x * d.x + d.y * d.y + d.z * d.z);
}

#endif